/*
 * Drawable2DInterface.cpp
 *
 *  Created on: Jul 6, 2009
 *      Author: kurt
 */

#include "Drawable2DInterface.h"
#include "DrawingCanvas.h"
#include <sstream>
using namespace std;
using namespace objdraw;

Drawable2DInterface::~Drawable2DInterface() 
{
	
}
Drawable2DInterface::Drawable2DInterface() 
{
	start = Location(0,0);
	end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
Drawable2DInterface::Drawable2DInterface(Drawable2DInterface const & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
float Drawable2DInterface::getHeight()
{
	if(start.y < end.y)
		return end.y - start.y;
	return start.y - end.y;
}
float Drawable2DInterface::getWidth()
{
	if(start.x < end.x)
		return end.x - start.x;
	return start.x - end.x;
}
Location Drawable2DInterface::getLocation()
{
	return start;
}
float Drawable2DInterface::getX()
{
	return start.x;
}
float Drawable2DInterface::getY()
{
	return start.y;
}
bool Drawable2DInterface::overlaps(Drawable2DInterface * item)
{
//	TODO overlaps
	return false;
}
bool Drawable2DInterface::contains(Location point)
{
	if(point.getX() >= start.getX() && point.getX() <= end.getX() 
		&& point.getY() >= start.getY() && point.getY() <= end.getY())
		return true;
	return false;
}
void Drawable2DInterface::move(float dx, float dy)
{
	start.translate(dx,dy);
	end.translate(dx,dy);
}
void Drawable2DInterface::moveTo(float x, float y)
{
	moveTo(Location(x,y));
}
void Drawable2DInterface::moveTo(Location point)
{
	float width = getWidth();
	float height = getHeight();
	start = point;
	end = Location(point.x + width, point.y + height);
}
string Drawable2DInterface::toString()
{
	stringstream rstr("Drawable2DInterface: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}
